const weather = require('../model/weather.model')

class weatherService {
  async createweather(data1) {
    let {id,data,time} = data1;
    var weather_list = data;
    var create_time = time;
    return await weather.create({id,weather_list,create_time})
  }

  async getweatherInfo(data) {
    let {id} = data;
    const res = await weather.findOne({
      attributes: ['id', 'weather_list','create_time'],
      where: {id},
    })
    return res ? res.dataValues : null
  }


  async findAlldata() {
    const res = await weather.findAll();
    return res;
  }

  async updateweather(data1) {
    // console.log("更新数据");
    const newdata = {};
    let {id,data,time} = data1;
    var weather_list = data;
    var create_time = time;
    weather_list && Object.assign(newdata, { weather_list });
    create_time && Object.assign(newdata, { create_time });
    // console.log(data);
    return await weather.update(newdata , { where: { id } })
  }
}

module.exports = new weatherService()
// attributes:["weather_id","weather_sn","add_time","weather_amount"],